extends Node2D

const BLOCK_SIZE := 60.0

@onready var teample: Line2D = $Line2D

var hor_lines:Array
var ver_lines:Array

func _ready() -> void:
	var rect = get_viewport_rect()
	for i in range(-rect.size.x/BLOCK_SIZE*2,10*rect.size.x/BLOCK_SIZE):
		var line2d = teample.duplicate(DUPLICATE_SCRIPTS)
		line2d.global_position.x += BLOCK_SIZE*i
		ver_lines.append(line2d)
		add_child(line2d)
	for i in range(-rect.size.y/BLOCK_SIZE*2,10*rect.size.y/BLOCK_SIZE):
		var line2d = teample.duplicate(DUPLICATE_SCRIPTS)
		line2d.global_position.y += BLOCK_SIZE*i
		hor_lines.append(line2d)
		add_child(line2d)
	GameEvents.player_in_build.connect(on_player_in_build)
	GameEvents.player_out_build.connect(on_player_out_build)

func on_player_in_build() -> void:
	for i in ver_lines.size():
		ver_lines[i].set_verline_animation(true)
	for i in hor_lines.size():
		hor_lines[i].set_horline_animation(true)
	
func on_player_out_build() -> void:
	for i in hor_lines.size():
		hor_lines[i].set_verline_animation(false)
	for i in ver_lines.size():
		ver_lines[i].set_horline_animation(false)
